package com.itdianzi.controller.company;

import com.github.pagehelper.PageInfo;
import com.itdianzi.controller.base.BaseController;
import com.itdianzi.domain.company.Company;
import com.itdianzi.service.company.CompanyService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/company")
public class CompanyController extends BaseController {
    @Autowired
    private CompanyService companyService;

    @RequestMapping(value = "/list",name = "企业数据查询")
    public String list(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "5") Integer size) {
            /*System.out.println(123);*/
        PageInfo pageInfo = companyService.findByPage(page,size);
        /*System.out.println(456);*/
        request.setAttribute("page",pageInfo);
        return "company/company-list";
    }

    @RequestMapping(value = "/toAdd",name = "企业添加")
    public String toAdd() {
        return "company/company-add";
    }

    @RequestMapping(value = "/edit",name = "企业添加或修改")
    public String edit(Company company) {
        if (StringUtils.isEmpty(company.getId())) {
            companyService.save(company);
        } else {
            companyService.upDate(company);
        }
        return "redirect:/company/list.do";
    }

    @RequestMapping(value = "/toUpdate",name = "跳转到修改页面并获取数据")
    public String toUpdate(String id) {
        Company company = companyService.findById(id);
        request.setAttribute("company",company);
        return "company/company-update";
    }

    @RequestMapping(value = "/delete",name = "企业删除")
    public String deleteById(String id) {
        companyService.deleteById(id);
        return "redirect:/company/list.do";
    }

  /*  @RequestMapping("/date")
    public String list(Date date) {
        *//*int i=1/0;*//*
        System.out.println(date);
        return "success";
    }*/
}
